package com.easy.venue.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.VenueBean;
import com.easy.common.service.IVenueService;
import com.easy.common.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/venue")
@CrossOrigin
public class VenueController {
    @Autowired
    IVenueService venueService;
    //管理员
    //添加场地信息
    @PostMapping("/add")
    public Result addVenue(@RequestBody VenueBean venue){
        int result = venueService.addVenue(venue);
        if(result >0 ){
            return Result.success(200,"添加场地信息成功",venue);
        }
        return Result.fail(400,"添加场地信息失败");
    }
    //查场地信息
    @GetMapping("/all")
    public Result getAll(VenueBean venue){
        Object venue_data = venueService.getAll(venue);
        return Result.success(venue_data);
    }
    //删除场地信息
    @DeleteMapping("/del/{id}")
    public Result deleteVenue(@PathVariable("id") Integer id){
        int result = venueService.deleteVenue(id);
        if(result>0){
            return Result.success("删除场地信息成功");
        }
        return Result.fail(400,"删除场地信息失败");
    }
    //修改场地信息
    @PutMapping("/update")
    public Result updateVenue(@RequestBody VenueBean venue){
        int result = venueService.updateVenue(venue);
        if(result>0){
            return Result.success("修改场地信息成功");
        }
        return Result.fail(400,"修改场地信息失败");
    }
    //分页查询
    @GetMapping("/page")
    public Result getPage(VenueBean venue, Page<VenueBean> page){
        venueService.getPage(venue,page);
        return Result.success(page);
    }
    @GetMapping("/getVenueById/{id}")
    public Result getVenueById(@PathVariable("id") Integer id){
        VenueBean venue = venueService.getVenueById(id);
        return Result.success(venue);
    }
}















